package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Name;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * the element hcontainer is a generic element for a hierarchical container. It can be placed in a hierarchy instead of
 * any of the other hierarchical containers. The attribute name is required and gives a name to the element.
 * 
 * <pre>
 * 	<xsd:element name="hcontainer">
 * 		<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="hierarchy">
 * 					<xsd:attributeGroup ref="name"/>
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class Hcontainer extends Hierarchy implements Name , HierElements{
	
	public static final String ELEMENT = "hcontainer";
	
	private String _name;

	/**
	 * @see org.akomantoso.core.data.attribute.Name#getName()
	 */
	@Override
	public String getName() {
		return _name;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Name#setName(java.lang.String)
	 */
	@Override
	public void setName(String name) {
		_name = name;
	}

	/**
	 * @see org.akomantoso.core.data.Hierarchy#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeName(out, this);
		super.writeExternal(out);
		out.writeEnd();
	}

	
	/**
	 * @see org.akomantoso.core.data.Hierarchy#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_name = in.readAttribute(Name.ATTRIBUTE);
		super.readExternal(in);
	}

	/**
	 * @see org.akomantoso.core.visitor.AKVisitable#accept(org.akomantoso.core.visitor.AKVisitor)
	 */
	@Override
	public void accept(AKVisitor visitor) {
		if (visitor.visitBegin(this)) {
			internalAccept(visitor);
			visitor.visitEnd(this);
		}
	}
	
}